#ifndef __MESSAGE_H__
#define __MESSAGE_H__
#include<string>
#include"public.h"
#include"timeStamp.h"
#include<sstream>

class Message
{
private:
    std::string m_coloredHeader;    //带颜色的，打印到终端里
    std::string m_commonHeader;     //不带颜色的，打印到日志文件里
    std::string m_msg;
private:
    /* 格式化颜色 */
    std::string formatFieldWithColor(COLOR_NUMBER colorNumber,
                                     bool dark,
                                     const std::string delimiter,
                                     const std::string fieldName,
                                     bool colored = true);
public:
    Message(LOG_LEVEL level,
            const std::string& fileName,
            const std::string& functionName,
            int lineNumber);
    /* [时间戳][日志级别][文件名称][函数名称][行号] */
    std::string FormatHeader(LOG_LEVEL level,
                             const std::string &fileName,
                             const std::string &functionName,
                             int lineNumber,
                             bool colored = true);
    std::string ToString(bool colored = true) const;
public:
    template<typename T>
    Message& operator<<(const T& t) {
        std::stringstream ss;
        ss << t;
        m_msg += ss.str();
        return *this;
    }
};

#endif